﻿global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc.Rendering;
global using Microsoft.AspNetCore.Mvc.TagHelpers;
global using Microsoft.AspNetCore.Mvc.ViewFeatures;
global using Microsoft.AspNetCore.Razor.TagHelpers;

global using WXWorkSvc.Common.Extensions;

using System.CodeDom;

namespace WXWorkSvc.Common.TagHelpers;
[HtmlTargetElement("input", Attributes = "asp-valid")]
public class InputTagHelper : TagHelper
{
    [HtmlAttributeNotBound]
    [ViewContext]
    public ViewContext ViewContext { get; set; } = default!;
    protected IHtmlGenerator HtmlGenerator;

    public InputTagHelper(IHtmlGenerator generator)
    {
        HtmlGenerator = generator;
    }

    [HtmlAttributeName("asp-for")]
    public ModelExpression For { get; set; } = default!;
    [HtmlAttributeName("asp-valid")]
    public string? Valid { get; set; } = null;

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        var tagInput = HtmlGenerator.GenerateTextBox(ViewContext, For.ModelExplorer, For.Name, For.Model, null, null);
        tagInput.MergeAttributes(context.Items);
        tagInput.Attributes.Add("for", For.Name);
        tagInput.Attributes.Add("data-valmsg-for", For.Name);
        tagInput.Attributes.Add("data-valmsg-replace", "false");

        output.Content.AppendHtml(tagInput);

    }

}


